package com.wanxing.sellerapp.config

import com.blankj.utilcode.util.SPUtils
import com.wanxing.sellerapp.App
import com.wanxing.sellerapp.config.entity.AppConfigEntry

object AppConfig {

    const val DEFAULT_SERVICE_URL = "http://121.199.55.133:8080"
    private const val DEFAULT_BROKER_URL = "tcp://121.199.55.133:1883"
    const val DEFAULT_CHANNEL = "test"
//    const val DEFAULT_CHANNEL = "local"
    const val callbackUrl = "http://121.199.55.133:8080/seller/oss/afterUpload"
    const val IZ_DEV = true

//    const val DEFAULT_SERVICE_URL = "http://sj4dn2.natappfree.cc"
//    private const val DEFAULT_BROKER_URL = "tcp://192.168.1.3:1883"
//    const val DEFAULT_CHANNEL = "local"
//    const val callbackUrl = "$DEFAULT_SERVICE_URL/seller/oss/afterUpload"

    const val LOGTAG = "SellerLog"
    var connPassword = "qwer1234"


    /**
     * 连接时需要的密码
     */
//    private const val DEFAULT_SERVICE_URL = "http://192.168.137.1:8080"
//    private const val DEFAULT_BROKER_URL = "tcp://192.168.137.1:1883"
//    private const val DEFAULT_CHANNEL = "local"

    const val BUCKET_NAME = "xyb2023"
    const val OSS_ENDPOINT = "http://oss-cn-hangzhou.aliyuncs.com"
    //视频存放地址
    const val VIDEO_SAVE_PATH = "/sdcard/SVideo/"
    //广告存放地址
    const val ADV_SAVE_PATH = "/sdcard/AVideo/"

    private const val KEY_CONFIG_RUN_ADV_APP = "CONFIG_RUN_ADV_APP"
    private const val KEY_CONFIG_VOLUME = "CONFIG_VOLUME"

    private const val KEY_CONFIG_BROKER_URL = "CONFIG_BROKER_URL"

    private const val KEY_CONFIG_SERVICE_URL = "CONFIG_SERVICE_URL"

    private const val KEY_CONFIG_CHANNEL = "CONFIG_CHANNEL"

    private const val KEY_CONFIG_CLEAR_SCALE_WHEN_BOOT = "CONFIG_CLEAR_SCALE_WHEN_BOOT"

    fun getAppConfig() = AppConfigEntry(runAdvAppOnStart, clearScaleWhenBoot)

    // 程序启动时，拉起广告程序
    var runAdvAppOnStart: Boolean
        set(value) = SPUtils.getInstance().put(KEY_CONFIG_RUN_ADV_APP, value,true)
        get() = SPUtils.getInstance().getBoolean(KEY_CONFIG_RUN_ADV_APP, false)

    // 程序音量
    var volume: Float
        set(value){
            SPUtils.getInstance().put(KEY_CONFIG_VOLUME, value,true)
            App.configModel.volume.postValue(value)
        }
        get() = SPUtils.getInstance().getFloat(KEY_CONFIG_VOLUME, 1F)

    var brokerUrl: String
        set(value){
            SPUtils.getInstance().put(KEY_CONFIG_BROKER_URL, value,true)
        }
        get() = SPUtils.getInstance().getString(KEY_CONFIG_BROKER_URL, DEFAULT_BROKER_URL)

    var channel: String
        set(value){
            SPUtils.getInstance().put(KEY_CONFIG_CHANNEL, value,true)
        }
        get() = SPUtils.getInstance().getString(KEY_CONFIG_CHANNEL, DEFAULT_CHANNEL)

    var clearScaleWhenBoot: Boolean
        set(value){
            SPUtils.getInstance().put(KEY_CONFIG_CLEAR_SCALE_WHEN_BOOT, value,true)
        }
        get() = SPUtils.getInstance().getBoolean(KEY_CONFIG_CLEAR_SCALE_WHEN_BOOT, false)

    fun getAdvUrl() = SPUtils.getInstance().getString("advUrl")
}